
from typing import List
# The Python Standard Modules(Library) and Third Modules(Library)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, ForeignKey, UniqueConstraint
from sqlalchemy import Integer, String, Date,Float,Boolean
from sqlalchemy.orm import Mapped,mapped_column,relationship,backref


from . import MappedBase


# ================================== 一对多 ================================== #
class Station(MappedBase):
    __tablename__ = 'station'

    def __repr__(self) -> str:
        return f'<Modele Station {self.name}>'

    id:Mapped[int]=mapped_column(primary_key=True, index=True, autoincrement=True, comment='主键id')
    name: Mapped[str] = mapped_column(String(20), unique=True,  nullable=False,comment='站点名称')
    # 站点的x坐标,可以为空,有时候就是没有,默认设置成0
    x: Mapped[float] = mapped_column(Float, default=0,nullable=True,comment='站点的x坐标')
    y: Mapped[float] = mapped_column(Float, default=0,nullable=True,comment='站点的x坐标')

    is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=1,comment='改站点是否禁用,0:禁用,1:启用')

    dev_id:Mapped[int]=mapped_column(ForeignKey("dev.id"),nullable=True,comment='该站点所述的设备id,可以是不属于任何设备的站点(暂且定位-1)')

    # 一个站点所述的设备
    # dev : Mapped['Dev'] =relationship("Dev",back_populates='stations',)
    # station_imgs: Mapped[List['Img']] = relationship(back_populates='station',cascade="all,delete-orphan")



